<?php
class KolSys_Chat_RegExp
{
	public $lastResult=null;
	public function getLastResult()
	{
		return $this->lastResult;
	}

	/*
		Sending a private message to someone via /msg
	*/
	public function isOutGoingPM($text)
	{
		$p=KolSys_RegExp::getObj("outgoingPrivate");
		$match=$p->match($text);
		if(!$match){return false;}
		$chat=array();
		$chat['type']='private';
		$chat['userName']=$match[2];
		$chat['userId']=(int)$match[1];
		$chat['text']=trim($match[3]);
		$chat['fullMatch']=$match[0];
		$chat['matchOffset']=$p->getMatchOffset();
		$this->lastResult=$chat;
		return true;
	}

	/*
		Typeing /c newChannel results in: You are now talking in channel: newChannel.
	*/
	public function isNewChannelChange($text)
	{
		$p=KolSys_RegExp::getObj("newChatChannel");
		$match=$p->match($text);
		if(!$match){return false;}
		$chat=array();
		$chat['type']='channel';
		$chat['currentChannel']=$match[1];
		$chat['description']=str_replace('<br>','',$match[2]);
		$chat['fullMatch']=$match[0];
		$chat['matchOffset']=$p->getMatchOffset();
		$this->lastResult=$chat;
		return true;
	}

	/*
		Typing /l results in: Currently listening to channels: channel a, channel b etc.
	*/
	public function isChatListenResponse($text)
	{
		$p=KolSys_RegExp::getObj("chatListenResponse");
		$match=$p->match($text);
		if(!$match){return false;}
		$chat=array();
		$listen=$match[0];
		$p1=KolSys_RegExp::getObj("chatListenCurrent");
		$p2=KolSys_RegExp::getObj("chatListenOthers");
		$match1=$p1->match($listen);
		$match2=$p2->matchAll($listen);
		$chat['type']='listen';
		$chat['currentChannel']=$match1[1];
		$chat['otherChannels']=$match2[1];
		$chat['fullMatch']=$match[0];
		$chat['matchOffset']=$p->getMatchOffset();
		$this->lastResult=$chat;
		return true;
	}

	/*
		Typing /l <channel> and getting "Now listening to channel: <channel>"
	*/
	public function isChatStartListen($text)
	{
		$p=KolSys_RegExp::getObj("chatStartListen");
		$match=$p->match($text);
		if(!$match){return false;}
		$chat=array();
		$chat['type']='listen:start';
		$chat['channel']=$match[1];
		$chat['fullMatch']=$match[0];
		$chat['matchOffset']=$p->getMatchOffset();
		$this->lastResult=$chat;
		return true;
	}

	/*
		Typing /l <channel> and getting "No longer listening to channel: <channel>"
	*/
	public function isChatStopListen($text)
	{
		$p=KolSys_RegExp::getObj("chatStopListen");
		$match=$p->match($text);
		if(!$match){return false;}
		$chat=array();
		$chat['type']='listen:stop';
		$chat['channel']=$match[1];
		$chat['fullMatch']=$match[0];
		$chat['matchOffset']=$p->getMatchOffset();
		$this->lastResult=$chat;
		return true;
	}

	/*
		e.g. [clan] Ultibot: hi clan
	*/
	public function isChatMessageWithLeadingChannelTag($text)
	{
	}

/*
chatStartListen : r'<font color=[^>]+>Now listening to channel: ([^>]+)</font>'
chatStopListen : r'<font color=[^>]+>No longer listening to channel: ([^>]+)</font>'
      chatListenPattern = PatternManager.getOrCompilePattern("chatListenResponse")
    "chatListenResponse" : r"<font color=[^>]+>Currently listening to channels:(.*?<b>.*?</b>.*?)</font>",
chatListenCurrent : r"<br>&nbsp;&nbsp;<b>(.*?)</b>"
chatListenOthers : r"&nbsp;&nbsp;([^<>]*?)<br>"
        if match:
            chat = {}
            listen = match.group()
            currentPattern = PatternManager.getOrCompilePattern("chatListenCurrent")
            otherPattern = PatternManager.getOrCompilePattern("chatListenOthers")
            chat["type"] = "listen"
            chat["currentChannel"] = currentPattern.search(listen).group(1)
            other = []
            for channel in otherPattern.finditer(listen):
                other.append(channel.group(1))
            chat["otherChannels"] = other
            text = text[:match.start()] + text[match.end():]
            chats.append(chat)
*/
}//class

__halt_compiler();
# Chat patterns.
    "currentChatChannel" : r'<font color="?#?\w+"?>Currently in channel: ([^<>]+)<',
    "chatLastSeen" : r"lastseen:([0-9]+)",
    "chatChannel" : r'^<font color="?#?\w+"?>\[([^<>]+)\]<\/font> ',
    "chatMessage" : r'<b><a target="?mainpane"? href="showplayer\.php\?who=(-?[0-9]+)"><font color="?#?\w+"?>([^<>]+)<\/font>(?:<\/b>|<\/a>|:)* (.*)$',
    "chatEmote" : r'<b><i><a target="?mainpane"? href="showplayer\.php\?who=([0-9]+)"><font color="?#?\w+"?>([^<>]+)<\/b><\/font><\/a> (.*)<\/i>$',
    "privateChat" : r'<a target="?mainpane"? href="showplayer\.php\?who=([0-9]+)"><font color="?blue"?><b>([^)]+) \(private\):<\/b><\/font><\/a> <font color="?blue"?>(.*)</font>$',
    "chatNewKmailNotification" : r'<a target="?mainpane"? href="messages\.php"><font color="?green"?>New message received from <a target="?mainpane"? href=\'showplayer\.php\?who=([0-9]+)\'><font color="?green"?>([^<>]+)<\/font><\/a>\.<\/font><\/a>$',
    "chatLink" : r'<a target="?_blank"? href="([^"]+)"><font color="?blue"?>\[link\]<\/font><\/a> ',
    "chatWhoResponse" : r'<table><tr><td class=tiny><center><b>Players in this channel:',
    "chatWhoPerson" : r'<a target="?mainpane"? href="showplayer\.php\?who=([0-9]+)"><font color="?#?\w+"?>([^<>]+)<\/font><\/a>',
    "chatLinkedPlayer" : r"<a style='color: #?\w+' href='showplayer\.php\?who=([0-9]+)' target=mainpane>([^<]+)<\/a>",
    "newChatChannel" : r"<font color=[^>]+>You are now talking in channel: ([^\,]+?)\.<p><p>(.*?)</font>",
    "chatListenResponse" : r"<font color=[^>]+>Currently listening to channels:(.*?<b>.*?</b>.*?)</font>",
    "chatListenCurrent" : r"<br>&nbsp;&nbsp;<b>(.*?)</b>",
    "chatListenOthers" : r"&nbsp;&nbsp;([^<>]*?)<br>",
    "chatStartListen" : r'<font color=[^>]+>Now listening to channel: ([^>]+)</font>',
    "chatStopListen" : r'<font color=[^>]+>No longer listening to channel: ([^>]+)</font>',
    "chatMultiLineStart" : r'<b><a target="?mainpane"? href="showplayer\.php\?who=(-?[0-9]+)"><font color="?#?\w+"?>([^<>]+)<\/font><\/b><\/a>:$',
    "chatMultiLineEmote" : r'<b><i><a target="?mainpane"? href="showplayer\.php\?who=(-?[0-9]+)"><font color="?#?\w+"?>([^<>]+)<\/b><\/font><\/a>$',
    "outgoingPrivate" : r'<font color="?blue"?><b>private to <a class=nounder target="?mainpane"? href="?showplayer.php\?who=([0-9]+)"?><font color="?blue"?>(.*?)</font></a></b>:(.*?)</font></br>',
    "chatPlayerLoggedOn" : r'<font color=green><a target=mainpane href=\'showplayer\.php\?who=([0-9]+)\'><font color=green><b>([^<>]+)<\/b><\/font><\/a> logged on\.<\/font>$',
    "chatPlayerLoggedOff" : r'<font color=green><a target=mainpane href=\'showplayer\.php\?who=([0-9]+)\'><font color=green><b>([^<>]+)<\/b><\/font><\/a> logged off\.<\/font>$',